package com.ayu.a.chapter02;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/**
 * @Author 徐林玉
 * @Description SelectionSort 选择排序
 * @Date 2022/11/3 11:34
 * @Version 1.0
 */
public class SelectionSort {

    public static void main(String[] args) {

        List<Integer> integers = selectSort(Lists.newArrayList(1, 55, 22, 44, 33, 546));

        integers.forEach(x-> System.out.print(x+"   "));

    }

    public static List<Integer> selectSort(ArrayList<Integer> arr){

        List<Integer> newArr = new ArrayList<>();
        while (arr.size()>0){

            Integer min = arr.get(0);
            int minIndex = 0;



            for (int i = 0; i < arr.size()-1; i++) {

                if(min>arr.get(i)){

                    min = arr.get(i);
                    minIndex = i;
                }

            }

            newArr.add(min);
            arr.remove(minIndex);

        }

        return newArr;


    }



}
